Attribute VB_Name = "Module1"
Global gsAccess As String
Global gsSQLServer As String
Global gsWelcome As String
Function VND(Amt) As String
    On Error GoTo err
    Dim Resp As String
    If Amt = 0 Then
      Resp = "Khoâng ñoàng"
    Else
      If Abs(Amt) > 999999999999.99 Then
        Resp = "Soá quaù lôùn"
      Else
        If Amt < 0 Then
          Resp = "Tröø  "
        Else
          Resp = Space(0)
        End If
        Tien = Format(Abs(Amt), "###########0.00")
        Tien = Right(Space(12) + Tien, 15)
        DOC = Space(0): Dem = DOC
        DOC = DOC + "traêm möôi  tyû   "
        DOC = DOC + "traêm möôi  trieäu"
        DOC = DOC + "traêm möôi  ngaøn "
        DOC = DOC + "traêm möôi  ñoàng "
        DOC = DOC + "traêm möôi  xu    "
        Dem = Dem + "moät hai  ba   boán naêm "
        Dem = Dem + "saùu baûy taùm chín "
        For i = 1 To 5
          Nhom = Mid(Tien, i * 3 - 2, 3)
          If Nhom <> Space(3) Then
            Select Case Nhom
              Case "000"
                If i = 4 Then
                  Chu = "ñoàng "
                Else
                  Chu = Space(0)
                End If
              Case ".00"
                Chu = "chaün"
              Case Else
                So1 = Left(Nhom, 1)
                So2 = Mid(Nhom, 2, 1)
                So3 = Right(Nhom, 1)
                Chu = Space(0)
                For j = 1 To 3
                  Dich = Space(0)
                  S = Val(Mid(Nhom, j, 1))
                  If S > 0 Then
                    Dich = Trim(Mid(Dem, S * 5 - 4, 5)) + " " + Trim(Mid(DOC, (i - 1) * 18 + j * 6 - 5, 6)) + " "
                  End If
                  Select Case j
                    Case 2 And S = 1
                      Dich = "möôøi "
                    Case 3 And S = 0 And Nhom <> Space(2) + "0"
                      Dich = Trim(Mid(DOC, (i - 1) * 18 + j * 6 - 5, 6)) + Space(1)
                    Case 3 And S = 5 And So2 <> Space(1) And So2 <> "0"
                      Dich = "l" + Mid(Dich, 2)
                    Case 2 And S = 0 And So3 <> "0"
                      If (So1 >= "1" And So1 <= "9") Or (So1 = "0" And i = 4) Then
                        Dich = "leû "
                      End If
                  End Select
                  Chu = Chu + Dich
                Next j
            End Select
            Vitri = InStr(1, Chu, "möôi moät", 1)
            If Vitri > 0 Then Mid(Chu, Vitri, 9) = "möôi moát"
            Resp = Resp + Chu
          End If
        Next i
      End If
    End If
    VND = UCase(Left(Resp, 1)) + Mid(Resp, 2)
    Exit Function
err:
    Beep
End Function
